package com.ffcs.cn.action.common;

import com.supermap.desktop.controls.ui.controls.colorSelect.SmButtonColorSelector;
import com.supermap.desktop.core.event.colorSelect.IColorChangedListener;
import com.supermap.desktop.core.ui.SmComboBoxFont;
import com.supermap.desktop.core.ui.controls.GridBagConstraintsHelper;
import com.supermap.desktop.core.ui.controls.SMSpinner;
import com.ffcs.cn.DevelopProperties;

import javax.swing.*;
import javax.swing.event.ChangeListener;
import java.awt.*;
import java.awt.event.ItemListener;

/**
 * 字体设置面板
 *
  */
public abstract class StyleSettingPanelText extends AbstractStyleSettingPanel {
	protected JLabel jLabelFontName; // 字体名称
	protected SmComboBoxFont smComboBoxFont;

	protected JLabel jLabelFontSize; // 大小
	protected SMSpinner smSpinnerFontSize;

	protected JLabel jLabelFontColor; // 文本颜色
	protected SmButtonColorSelector smButtonColorSelector;

	protected JCheckBox checkBoxBold; // 加粗
	protected JCheckBox checkBoxStrikeOut; // 删除线
	protected JCheckBox checkBoxShadow; // 阴影
	protected JCheckBox checkBoxUnderLine; // 下划线
	protected JCheckBox checkBoxOutline; // 轮廓
	protected JCheckBox checkBoxBackOpaque; // 背景透明
	protected JCheckBox checkBoxRightItalic; // 右斜体
	protected JCheckBox checkBoxLeftItalic; // 左斜体
	protected JCheckBox checkBoxFixedSize; // 固定大小

	public static final double Right_ITALIC = 15D;
	public static final double LEFT_ITALIC = -15D;

	public StyleSettingPanelText() {
		initComponents();
		initLayout();
		registerEvents();
	}

	private void initComponents() {
		jLabelFontName = new JLabel(DevelopProperties.getString("String_Label_FontName"));
		jLabelFontSize = new JLabel(DevelopProperties.getString("String_Label_FontSize"));
		jLabelFontColor = new JLabel(DevelopProperties.getString("String_Label_FontColor"));

		smComboBoxFont = new SmComboBoxFont();
		smSpinnerFontSize = new SMSpinner();
		smButtonColorSelector = new SmButtonColorSelector();
		checkBoxBold = new JCheckBox(DevelopProperties.getString("String_Bold"));
		checkBoxStrikeOut = new JCheckBox(DevelopProperties.getString("String_StrikeOut"));
		checkBoxShadow = new JCheckBox(DevelopProperties.getString("String_Shadow"));
		checkBoxUnderLine = new JCheckBox(DevelopProperties.getString("String_UnderLine"));
		checkBoxOutline = new JCheckBox(DevelopProperties.getString("String_OutLine"));
		checkBoxBackOpaque = new JCheckBox(DevelopProperties.getString("String_BackOpaque"));
		checkBoxRightItalic = new JCheckBox(DevelopProperties.getString("String_RightItalic"));
		checkBoxLeftItalic = new JCheckBox(DevelopProperties.getString("String_LeftItalic"));
		checkBoxFixedSize = new JCheckBox(DevelopProperties.getString("String_FixedSize"));
	}

	private void initLayout() {
		this.setLayout(new GridBagLayout());
		this.add(jLabelFontName, new GridBagConstraintsHelper(0, 0, 1, 1)
				.setAnchor(GridBagConstraints.WEST)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP)
				.setFill(GridBagConstraints.NONE)
				.setWeight(0, 0));
		this.add(smComboBoxFont, new GridBagConstraintsHelper(1, 0, 1, 1)
				.setAnchor(GridBagConstraints.WEST)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP)
				.setFill(GridBagConstraints.HORIZONTAL)
				.setWeight(1, 0));

		this.add(jLabelFontSize, new GridBagConstraintsHelper(0, 1, 1, 1)
				.setAnchor(GridBagConstraints.WEST)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP)
				.setFill(GridBagConstraints.NONE)
				.setWeight(0, 0));
		this.add(smSpinnerFontSize, new GridBagConstraintsHelper(1, 1, 1, 1)
				.setAnchor(GridBagConstraints.WEST)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP)
				.setFill(GridBagConstraints.HORIZONTAL)
				.setWeight(1, 0));

		this.add(jLabelFontColor, new GridBagConstraintsHelper(0, 2, 1, 1)
				.setAnchor(GridBagConstraints.WEST)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP)
				.setFill(GridBagConstraints.NONE)
				.setWeight(0, 0));
		this.add(smButtonColorSelector, new GridBagConstraintsHelper(1, 2, 1, 1)
				.setAnchor(GridBagConstraints.WEST)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP)
				.setFill(GridBagConstraints.HORIZONTAL)
				.setWeight(1, 0));
		JPanel panelCheckBox = new JPanel();
		panelCheckBox.setBorder(BorderFactory.createTitledBorder(DevelopProperties.getString("String_FontEffect")));
		panelCheckBox.setLayout(new GridBagLayout());
		panelCheckBox.add(checkBoxBold, new GridBagConstraintsHelper(0, 0, 1, 1)
				.setAnchor(GridBagConstraints.WEST)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP)
				.setFill(GridBagConstraints.NONE)
				.setWeight(0, 0));
		panelCheckBox.add(checkBoxStrikeOut, new GridBagConstraintsHelper(0, 1, 1, 1)
				.setAnchor(GridBagConstraints.WEST)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP)
				.setFill(GridBagConstraints.NONE)
				.setWeight(0, 0));
		panelCheckBox.add(checkBoxShadow, new GridBagConstraintsHelper(1, 0, 1, 1)
				.setAnchor(GridBagConstraints.WEST)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP)
				.setFill(GridBagConstraints.NONE)
				.setWeight(0, 0));
		panelCheckBox.add(checkBoxUnderLine, new GridBagConstraintsHelper(1, 1, 1, 1)
				.setAnchor(GridBagConstraints.WEST)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP)
				.setFill(GridBagConstraints.NONE)
				.setWeight(0, 0));
		panelCheckBox.add(checkBoxOutline, new GridBagConstraintsHelper(2, 0, 1, 1)
				.setAnchor(GridBagConstraints.WEST)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP)
				.setFill(GridBagConstraints.NONE)
				.setWeight(0, 0));
		panelCheckBox.add(checkBoxBackOpaque, new GridBagConstraintsHelper(2, 1, 1, 1)
				.setAnchor(GridBagConstraints.WEST)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP)
				.setFill(GridBagConstraints.NONE)
				.setWeight(0, 0));
		panelCheckBox.add(checkBoxRightItalic, new GridBagConstraintsHelper(3, 0, 1, 1)
				.setAnchor(GridBagConstraints.WEST)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP)
				.setFill(GridBagConstraints.NONE)
				.setWeight(0, 0));
		panelCheckBox.add(checkBoxFixedSize, new GridBagConstraintsHelper(3, 1, 1, 1)
				.setAnchor(GridBagConstraints.WEST)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP)
				.setFill(GridBagConstraints.NONE)
				.setWeight(0, 0));
		panelCheckBox.add(checkBoxLeftItalic, new GridBagConstraintsHelper(4, 0, 1, 1)
				.setAnchor(GridBagConstraints.WEST)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP)
				.setFill(GridBagConstraints.NONE)
				.setWeight(0, 0));
		this.add(panelCheckBox, new GridBagConstraintsHelper(0, 3, 2, 1)
				.setAnchor(GridBagConstraints.WEST)
				.setInsets(GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.CONTROLS_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP)
				.setFill(GridBagConstraints.HORIZONTAL)
				.setWeight(1, 1));
	}

	private void registerEvents() {
		smComboBoxFont.addItemListener(getFontNameChangeListener());
		smSpinnerFontSize.addChangeListener(getFontSizeChangeListener());
		smButtonColorSelector.addColorChangedListener(getFontColorChangeListener());
		checkBoxBold.addChangeListener(getBoldChangeListener());
		checkBoxBackOpaque.addChangeListener(getBackgroundTransparencyListener());
		checkBoxFixedSize.addChangeListener(getFixedSizeChangeListener());
		checkBoxShadow.addChangeListener(getShadowChangeListener());
		checkBoxOutline.addChangeListener(getOutLineChangeListener());
		checkBoxUnderLine.addChangeListener(getUnderLineChangeListener());
		checkBoxLeftItalic.addChangeListener(getLeftItalicListener());
		checkBoxRightItalic.addChangeListener(getRightItalicListener());
		checkBoxStrikeOut.addChangeListener(getStrikeOutListener());
	}

	public abstract ItemListener getFontNameChangeListener();

	public abstract ChangeListener getFontSizeChangeListener();

	public abstract IColorChangedListener getFontColorChangeListener();

	public abstract ChangeListener getBoldChangeListener();

	public abstract ChangeListener getBackgroundTransparencyListener();

	public abstract ChangeListener getFixedSizeChangeListener();

	public abstract ChangeListener getShadowChangeListener();

	public abstract ChangeListener getOutLineChangeListener();

	public abstract ChangeListener getUnderLineChangeListener();

	public abstract ChangeListener getLeftItalicListener();

	public abstract ChangeListener getRightItalicListener();

	public abstract ChangeListener getStrikeOutListener();
}
